package 单周赛.history;

import java.util.*;

/**
 *
 */
public class 第287场单周赛 {

    public static void main(String[] args) {

        System.out.println(convertTime("02:30", "04:35"));

        int[][] matchs = {{2, 3}, {1, 3}, {5, 4}, {6, 4}};
        System.out.println(findWinners(matchs));

    }

    /**
     * 6055. 转化时间需要的最少操作数
     *
     * @param current
     * @param correct
     * @return
     */
    public static int convertTime(String current, String correct) {
        int ans = 0;

        int[] times = {60, 15, 5, 1};
        int curMinute = Integer.valueOf(current.substring(0, 2)) * 60 +
                Integer.valueOf(current.substring(3, 5));
        int toMinute = Integer.valueOf(correct.substring(0, 2)) * 60 +
                Integer.valueOf(correct.substring(3, 5));

        while (toMinute - curMinute > 0) {
            for (int time : times) {
                if (toMinute - curMinute >= time) {
                    curMinute += time;
                    ans++;
                    break;
                }
            }
        }
        return ans;
    }

    /**
     * 5235. 找出输掉零场或一场比赛的玩家
     *
     * @param matches
     * @return
     */
    public static List<List<Integer>> findWinners(int[][] matches) {
        List<List<Integer>> lists = new ArrayList<>();
        List<Integer> fail0List = new ArrayList<>();
        List<Integer> fail1List = new ArrayList<>();
        lists.add(fail0List);
        lists.add(fail1List);

        Arrays.sort(matches, (o1, o2) -> o1[0] - o2[0]);
        Set<Integer> winSet = new LinkedHashSet<>();
        Map<Integer, Integer> failMap = new HashMap<>();

        for (int[] match : matches) {
            winSet.add(match[0]);
            failMap.put(match[1], failMap.getOrDefault(match[1], 0) + 1);
        }

        for (Integer win : winSet) {
            if (!failMap.containsKey(win)) {
                fail0List.add(win);
            }
        }

        for (Integer fail : failMap.keySet()) {
            if (failMap.get(fail) == 1) {
                fail1List.add(fail);
            }
        }
        fail1List.sort((o1, o2) -> o1 - o2);
        return lists;
    }

}
